Assume that a `build.rs` file is a build script
authorPaul Woolcock <paul@woolcock.us>
Tue, 7 Feb 2017 17:41:36 +0000 (12:41 -0500)
committerPaul Woolcock <paul@woolcock.us>
Tue, 7 Feb 2017 17:41:36 +0000 (12:41 -0500)
If cargo sees a `build.rs` file in the same directory as the current
`Cargo.toml`, it will assume that the `build.rs` file is a build script,
_unless there is_ `build = false` _in the _ `Cargo.toml` _file_.

Closes #3391

src/cargo/util/toml.rs
tests/build-script.rs

index 3cb35184da7da3d7447b82595d322d921ec506c3..d12c73c679ebed73127ac2b264bd6f5b0286096c 100644 (file)
@@ -534,7 +534,7 @@ impl TomlManifest {
         }
 
         // processing the custom build script
-        let new_build = self.maybe_custom_build(&project.build, &layout.root, &mut warnings);
+        let new_build = self.maybe_custom_build(&project.build, &layout.root);
 
         // Get targets
         let targets = normalize(&layout.root,
@@ -768,8 +768,7 @@ impl TomlManifest {
 
     fn maybe_custom_build(&self,
                           build: &Option<StringOrBool>,
-                          project_dir: &Path,
-                          warnings: &mut Vec<String>)
+                          project_dir: &Path)
                           -> Option<PathBuf> {
         let build_rs = project_dir.join("build.rs");
         match *build {
@@ -778,15 +777,9 @@ impl TomlManifest {
             Some(StringOrBool::String(ref s)) => Some(PathBuf::from(s)),
             None => {
                 match fs::metadata(&build_rs) {
-                    // Enable this after the warning has been visible for some time
-                    // Ok(ref e) if e.is_file() => Some(build_rs.into()),
-                    Ok(ref e) if e.is_file() => {
-                        warnings.push("`build.rs` files in the same directory \
-                                       as your `Cargo.toml` will soon be treated \
-                                       as build scripts. Add `build = false` to \
-                                       your `Cargo.toml` to prevent this".into());
-                        None
-                    },
+                    // If there is a build.rs file next to the Cargo.toml, assume it is
+                    // a build script
+                    Ok(ref e) if e.is_file() => Some(build_rs.into()),
                     Ok(_) => None,
                     Err(_) => None,
                 }
index 74297a86e351743ad69e20a2ad06dcebcdb9a895..b0a17a489f7b4d63ca19fe2e11846f88e8fcdafa 100644 (file)
@@ -2350,8 +2350,8 @@ fn assume_build_script_when_build_rs_present() {
         "#)
         .file("src/main.rs", r#"
             fn main() {
-                if cfg!(foo) {
-                    panic!("the build script was run");
+                if cfg!(foo) {
+                    panic!("the build script was not run");
                 }
             }
         "#)
@@ -2363,14 +2363,7 @@ fn assume_build_script_when_build_rs_present() {
     p.build();
 
     assert_that(p.cargo("run").arg("-v"),
-                execs().with_status(0).with_stderr("\
-warning: `build.rs` files in the same directory as your `Cargo.toml` will soon be treated \
-as build scripts. Add `build = false` to your `Cargo.toml` to prevent this
-   Compiling builder v0.0.1 ([..])
-     Running [..]
-    Finished [..]
-     Running [..]
-"));
+                execs().with_status(0));
 }
 
 #[test]